package main

import (
	"gitee.com/goxiang2/server/lib/lib_rpc"
	"github.com/golang/protobuf/proto"
	pb "gitee.com/goxiang2/server/benchmark/rpc/proto"
	"log"
	"time"
)

func testRpc(n, c, t int) {
	req := &pb.AddReq{123123, 3}
	buff, _ := proto.Marshal(req)
	ch := make(chan int, 1)

	begin := time.Now().Unix()
	for i := 0; i < n; i++ {
		conn, _ := lib_rpc.Dial("tcp", "127.0.0.1:12323")

		for j := 0; j < c; j++ {
			go func() {
				for k := 0; k < t; k++ {
					conn.RawCall("AddServer.Add", buff)
				}

				ch <- 1
			}()
		}
	}

	for i := 0; i < c*n; i++ {
		<-ch
	}
	log.Println(n*c*t, time.Now().Unix()-begin)
}

func main() {
	testRpc(1, 1, 1000000)
	testRpc(1, 10, 100000)
	testRpc(10, 1, 100000)
	testRpc(10, 10, 10000)
	testRpc(10, 100, 10000)
}
